package tenantchannellogic

import (
	"context"

	model "gitee.com/liuxuezhan/ar-platform/assets-rpc/internal/dao/model/tenant/channel"
	"gitee.com/liuxuezhan/ar-platform/assets-rpc/pkg/xerrors"

	"gitee.com/liuxuezhan/ar-platform/assets-rpc/internal/svc"
	"gitee.com/liuxuezhan/ar-platform/assets-rpc/rpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type QrBankInfoLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewQrBankInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *QrBankInfoLogic {
	return &QrBankInfoLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *QrBankInfoLogic) QrBankInfo(in *rpc.QrBankInfoRequest) (*rpc.QrBankInfoResponse, error) {
	var CommonResp rpc.CommonResp

	qrBankModel := model.NewTenantChannelQrBankModel(l.ctx, l.svcCtx.Db)
	qrBank, err := qrBankModel.GetQrBankById(in.Id)
	if err != nil {
		CommonResp.Code = xerrors.DBError
		CommonResp.Message = "Database operation error"
		return &rpc.QrBankInfoResponse{
			CommonResp: &CommonResp,
		}, err
	}

	return &rpc.QrBankInfoResponse{
		Id:           qrBank.ID,
		CreatedAt:    qrBank.CreatedAt,
		UpdatedAt:    qrBank.UpdatedAt,
		MinAmount:    qrBank.MinAmount,
		MaxAmount:    qrBank.MaxAmount,
		DailyTimes:   qrBank.DailyTimes,
		DailyAmount:  qrBank.DailyAmount,
		RemainTimes:  qrBank.RemainTimes,
		RemainAmount: qrBank.RemainAmount,
		VisionLevel:  qrBank.VisionLevel,
		IsDisplay:    qrBank.IsDisplay,
		QrCode:       qrBank.QrCode,
		BankNickname: qrBank.BankNickname,
		BankName:     qrBank.BankName,
		Sort:         qrBank.Sort,
		Remark:       qrBank.Remark,
		CommonResp:   &CommonResp,
	}, nil
}
